package cn.kgb.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import cn.kgb.javabean.User;
import cn.kgb.util.DataAccess;




public class LoginDAO {

	public User logIn(String user, String password) {
		
         Connection con = DataAccess.getConnection();
         String sql = "select * from myjavamail_username where username='"
                      + user+"' AND password ='"
                      + password+"'";
         Statement stmt;
		try {
			stmt = con.createStatement();
			ResultSet rs = stmt.executeQuery(sql);
	         while (rs.next()){
	         User pu= new User();
	        
	         pu.setId(rs.getInt("id"));
	         pu.setUsername(rs.getString("username"));
	         pu.setPassword(rs.getString("password"));
	         pu.setNikename(rs.getString("nikename"));
	         pu.setPhone(rs.getString("phone"));
	         pu.setEmail(rs.getString("email"));
	         pu.setServices(rs.getString("services"));
	         pu.setLevel(rs.getInt("level"));
	         return pu;
	         }
	        
	         rs.close();
	         stmt.close();
	         con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
         return null;
   }
	 
}
